import Home from '../views/Home.vue'


export default [
    {
      path: '/',
      alias: '/home_page',  //起别名
      name: 'Home',
      component: Home,
      props: route => ({
          food: route.query.food
      }),
    //   独享路由守卫
      beforeEnter:(to,from,next)=>{
        if(from.name === 'login') 
            alert('这是从登录页来的')
        else 
        // alert('这不是从登录页来的')
        next()
      }
    },
    {
      path: '/about',
      name: 'About',
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import(/* webpackChunkName: "about" */ '../views/About.vue'),
      props: {
          food: 'banana'
      },
      //路由元信息 (每一个路由对象可以配置一个meta字段)
      meta: {
        title: '关于'
      }
    },
    {
        path: '/argu/:name',
        component: ()=>import('@/views/argu.vue'),
        props: true
    },
    {
        path: '/parent',
        name: 'parent',
        component: ()=>import('@/views/parent.vue'),
        children: [
            {
                //注意没有 "/"
                path: 'child',          
                component:()=>import('@/views/child.vue')
            }
        ]
    },
    {
        path: '/named_view',
        components: {
            default: ()=>import('@/views/child.vue'),
            email: ()=>import('@/views/email.vue'),
            tel: ()=>import('@/views/tel.vue')
        }
    },
    {
        // 查看控制台输出
        path: '/to',
        redirect: to =>{
            // console.log(to)
            return {
                // name: 'Home'
                path: '/'
            }
        }
    },
    {
        path: "/login",
        name: 'login',
        component: ()=>import('@/views/login.vue')
    },
    {
        path: '/store',
        component:()=>import('@/views/store.vue')
    },
    {
        path: '*',
        component: ()=>import('@/views/error_404.vue')
    }
  ]